<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" width="70vw" destroy-on-close @closed="$emit('closed')" align-center :close-on-click-modal="false" draggable overflow>
        <el-container>
            <el-header>
                <div class="left-panel">
                    <el-button type="primary" @click="back">确定</el-button>
                </div>
            </el-header>
            <el-main class="nopadding">
                <scTable ref="table" row-key="id" :data="data" @selection-change="selectionChange" @row-dblclick="dbselectionChange" stripe hidePagination hideDo border height="650" :cell-style="cellStyle">
                    <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
                    <el-table-column type="index" label="" fixed align="center" width="50"></el-table-column>
                    <el-table-column label="花型名称" prop="flower"></el-table-column>
                    <el-table-column label="图片" align="center" prop="flower_image">
                        <template #default="scope">
                            <el-image v-if="scope.row.flower_image" style="width: 50px; height: 50px; border-radius: 5px;" :src="scope.row.flower_image" :preview-src-list="[scope.row.flower_image]" preview-teleported="true" hide-on-click-modal align="center"></el-image>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>
        </el-container>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
        </template>
    </el-dialog>
</template>

<script>
import saveAdd from './save.vue'

export default {
    components: {saveAdd},
    emits: ['success', 'closed'],
    data() {
        return {
            mode: "add",
            titleMap: {
                add: '选择花型',
                edit: '选择花型',
                show: '查看'
            },
            visible: false,
            isSaveing: false,
			selection: [],
            data: [],
            is_select: [],
        }
    },
    mounted() {
    },
    methods: {
        cellStyle(row){
            let data = row.row
            let cellStyle = '';
            switch(this.is_select.includes(data.flower)){
                case true:
                    cellStyle = {backgroundColor:'#c8e7d1'}
                    break;
                default:
                    cellStyle = {backgroundColor:'#ffffff'}
            }
            return cellStyle
        },
        // 显示
        open(mode = 'add') {
            this.mode = mode;
            this.visible = true;
            return this
        },
        // 选择事件
        selectionChange(selection) {
            this.selection = selection;
        },
        dbselectionChange(selection){
            this.$emit('success', [selection], this.type)
            this.visible = false;
        },
        // 选中返回
        back() {
            this.$emit('success', this.selection, this.type)
            this.visible = false;
        },
        async setData(data) {
            this.is_select = data.is_select
            let query = { apply_id: data.apply_id,goods_id: data.goods_id, }
            var res = await this.$API.basic.shopApply.detail.get(query)
            this.data = res.data.flower_data
		},
    }
}
</script>

<style></style>
